package org.example.day06;

/**
 * 第二章节:2.3.1: 关键字volatile与死循环
 */
public class MyThread {
    private boolean isContinuePrint = true;

    public boolean isContinuePrint() {
        return isContinuePrint;
    }

    public void setContinuePrint(boolean continuePrint) {
        isContinuePrint = continuePrint;
    }

    public void printMethod(){
        try {
            while(isContinuePrint == true){
                System.out.println("threadName = " + Thread.currentThread().getName());
                Thread.sleep(1000);
            }
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        MyThread m1 = new MyThread();
        m1.printMethod();
        //程序一直卡在 m1.printMethod(); 进入死循环
        System.out.println("停止！~" + Thread.currentThread().getName());
        m1.setContinuePrint(false);
    }
}
